<%@ page contentType="text/html;charset=UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<c:set var="az" value="${pageContext.request.contextPath}" />
<!DOCTYPE html>
<html lang="zh-cn">
<head>
    <meta charset="utf-8">
    <meta http-equiv="Pragma" content="no-cache">
    <meta http-equiv="Cache-Control" content="no-cache">
    <meta http-equiv="Expires" content="0">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <title>首页-框架页</title>

    <%@include file="/view/common/common-href.jsp" %>

    <style>
        html, body {
            height:100%; padding:0; margin:0;
        }
        .panel-header, .panel-body {
            border-width: 0px;
            border-style: solid;
        }
    </style>

</head>

<body>
    <div id="tb">
        <form id="searchForm">
            <div style="margin:5px 0 0 5px;">
                <%--时间范围: <input class="easyui-datebox" style="width:120px">
                至: <input class="easyui-datebox" style="width:120px">--%>
                顶部菜单:
                <select name="rootUid" id="rootUid" class="easyui-combobox" panelHeight="auto" style="width:100px"
                        data-options="
                            valueField: 'uid',
                            textField: 'funName',
                            panelHeight:'auto',
                            url:'/sys/menu/menuTree?_m=load&funType=top&all=search',
                            editable:false">
                </select>
                状态:
                <select name="lockStatus" id="lockStatus" class="easyui-combobox" panelHeight="auto" style="width:100px">
                    <option value="-1">全部状态</option>
                    <option value="0">未锁定</option>
                    <option value="1">已锁定</option>
                </select>
            </div>
        </form>
        <div style="height:auto; margin:5px 0 0 0;">
            <a href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true" onclick="searchLoad()"><i class="fa fa-search"></i>搜索</a>
            <a href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true" onclick="addTopInit();"><i class="fa fa-plus-square"></i>&nbsp;添加</a>
            <a href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true" onclick="editTopInit()"><i class="fa fa-edit"></i>&nbsp;编辑</a>
            <a href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true" onclick="orderTopUp()"><i class="fa fa-edit"></i>&nbsp;上移</a>
            <a href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true" onclick="orderTopDown()"><i class="fa fa-edit"></i>&nbsp;下移</a>
            <a href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true" onclick="menuLock()"><i class="fa fa-lock"></i>&nbsp;冻结</a>
            <a href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true" onclick="menuUnLock()"><i class="fa fa-unlock-alt"></i>&nbsp;解冻</a>
            <a href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true" onclick="deleteTopInit()"><i class="fa fa-trash-o"></i>&nbsp;删除</a>
            <%--<a href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true" onclick="addLeftInit();"><i class="fa fa-plus-square"></i>&nbsp;添加左侧菜单</a>--%>
        </div>
    </div>

    <table id="tt" class="easyui-datagrid" title="Basic DataGrid" style="height:100%; margin:5px 0 0 0;"
           data-options="
                singleSelect:true, collapsible:true, fit:true, noheader:true,
                pagination:true, pageSize:10, rownumbers:true,
                method:'post', toolbar:'#tb',
                url:'/sys/menuLeft/search?_m=load'">
        <thead>
            <tr>
                <th data-options="field:'funName',width:150,align:'center'">菜单名称</th>
                <th data-options="field:'lockStatus',width:80,align:'center',
                    formatter: function(value, row, index) {
                        if (value==0){
                            return '未锁定';
                        } else if(value==1) {
                            return '已锁定';
                        } else {
                            return '未知状态';
                        }
                    }
                ">使用状态</th>
                <th data-options="field:'relOrder',width:80,align:'center'">排序</th>
                <th data-options="field:'rootName',width:150,align:'center'">顶部菜单</th>
                <th data-options="field:'icon',width:120,align:'center'">图标</th>
                <th data-options="field:'createAt',width:200,align:'center',
                    formatter: function(value, row, index) {
                        return new Date(value).format('yyyy-MM-dd hh:mm:ss');
                    }
                ">添加时间</th>
                <th data-options="field:'remark',width:150,align:'center'">描述</th>
            </tr>
        </thead>
    </table>
</body>

</html>
<script type="text/javascript">

    var $obj = {width:800, height:320, modal:true, onClose:function() { $(this).dialog('destroy'); } };
    var $viewDialog;
    var $viewDatagrid = $("#tt");

    // 添加
    function addTopInit() {
        $obj.href = '/sys/menuLeft/insert?_m=init';
        $obj.title = '<i class="fa fa-th-large"></i><span class="dialog-title">&nbsp;添加左侧菜单<span>';
        $obj.datagrid = $viewDatagrid;
        $obj.buttons = [
            { type: 'save', text:'<i class="fa fa-floppy-o" aria-hidden="true"></i>&nbsp;保 存', width:'70px' },
            { type: 'back', text:'<i class="fa fa-reply" aria-hidden="true"></i>&nbsp;返 回', width:'70px' }
        ];

        $AzerothData.methods.dialogAdd($obj);
    }

    // 编辑
    function editTopInit() {
        $obj.href = '/sys/menuLeft/update?_m=init';
        $obj.title = '<i class="fa fa-th-large"></i><span class="dialog-title">&nbsp;编辑左侧菜单<span>';
        $obj.datagrid = $viewDatagrid;
        $obj.buttons = [
            { type: 'save', text:'<i class="fa fa-floppy-o" aria-hidden="true"></i>&nbsp;保 存', width:'70px' },
            { type: 'back', text:'<i class="fa fa-reply" aria-hidden="true"></i>&nbsp;返 回', width:'70px' }
        ];

        $AzerothData.methods.dialogEdit($obj);

    }

    // 排序上移
    function orderTopUp() {
        var row = $viewDatagrid.datagrid('getSelected');
        if(row==null){
            parent.$.messager.alert("提示", $AzerothData.methods.errorMsg("请选择一行数据！"), "error");
            return;
        }

        $obj.href = '/sys/menu/order?_m=exec&type=1';
        $obj.title = null;
        $obj.datagrid = $viewDatagrid;
        $obj.buttons = null;
        $obj.msg = '是否要上移菜单';
        $obj.prompt = '上移成功';

        //获取当前行索引
        var rowIndex = $viewDatagrid.datagrid('getRowIndex', row);
        if(rowIndex == 0) {
            parent.$.messager.alert("提示","排序已在最上","info", function() {});
            return;
        } else {
            var nextRow = $viewDatagrid.datagrid('getData').rows[rowIndex-1];
            $obj.field = {uid : row.uid, nextuid: nextRow.uid, orderFunType: 'up'}
        }
        $AzerothData.methods.dialogAjax($obj);

    }

    // 排序下移
    function orderTopDown() {
        var row = $viewDatagrid.datagrid('getSelected');
        if(row==null){
            parent.$.messager.alert("提示", $AzerothData.methods.errorMsg("请选择一行数据！"), "error");
            return;
        }

        $obj.href = '/sys/menu/order?_m=exec&type=1';
        $obj.title = null;
        $obj.datagrid = $viewDatagrid;
        $obj.buttons = null;
        $obj.msg = '是否要下移菜单';
        $obj.prompt = '下移成功';

        //获取当前行索引
        var rowIndex = $viewDatagrid.datagrid('getRowIndex', row);
        var lastIndex = $viewDatagrid.datagrid('getData').rows.length-1;
        if(rowIndex == lastIndex) {
            parent.$.messager.alert("提示","排序已在最下","info", function() {});
            return;
        } else {
            var nextRow = $viewDatagrid.datagrid('getData').rows[rowIndex+1];
            $obj.field = {uid : row.uid, nextuid: nextRow.uid, orderFunType: 'down'};
        }
        $AzerothData.methods.dialogAjax($obj);

    }

    // 删除
    function deleteTopInit() {
        $obj.href = '/sys/menuLeft/delete?_m=exec';
        $obj.title = null;
        $obj.datagrid = $viewDatagrid;
        $obj.buttons = null;
        $obj.msg = '是否要删除菜单';

        $AzerothData.methods.dialogDelete($obj);
    }

    // 冻结
    function menuLock() {
        var row = $viewDatagrid.datagrid('getSelected');
        if(row==null){
            parent.$.messager.alert("提示", $AzerothData.methods.errorMsg("请选择一行数据！"), "error");
            return;
        }

        if(row.lockStatus=="1") {
            parent.$.messager.alert("提示", "菜单已经冻结", "error");
            return;
        }

        $obj.href = '/sys/menu/lockLeft?_m=exec';
        $obj.title = null;
        $obj.datagrid = $viewDatagrid;
        $obj.buttons = null;
        $obj.msg = '是否要冻结菜单';
        $obj.prompt = '冻结成功';
        $obj.field = {uid : row.uid}

        $AzerothData.methods.dialogAjax($obj);
    }

    // 解冻
    function menuUnLock() {
        var row = $viewDatagrid.datagrid('getSelected');
        if(row==null){
            parent.$.messager.alert("提示", $AzerothData.methods.errorMsg("请选择一行数据！"), "error");
            return;
        }

        if(row.lockStatus=="0") {
            parent.$.messager.alert("提示", "菜单已经解冻", "error");
            return;
        }

        $obj.href = '/sys/menu/unlockLeft?_m=exec';
        $obj.title = null;
        $obj.datagrid = $viewDatagrid;
        $obj.buttons = null;
        $obj.msg = '是否要解冻菜单';
        $obj.prompt = '解冻成功';
        $obj.field = {uid : row.uid}

        $AzerothData.methods.dialogAjax($obj);
    }

    // 点击搜索
    function searchLoad() {
        $('#tt').datagrid('load', $AzerothData.methods.serializeObject($("#searchForm").form()));
    }

</script>